﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.IO;
using System.Windows.Forms;
using Autodesk.Revit.DB;
using YArchitech.LIB;
using YArchitech.LIB.YJKControls;
using YJKCodeBase.XmlUtility;

namespace ModelChecking.ModelValidation.ClearHeightCheck
{
	public partial class CheckTypeSelectForm : System.Windows.Forms.Form
	{
		public CheckTypeSelectForm(List<Element> elementList)
		{
			this.InitializeComponent();
			//base.Icon = Resource.YArchitechIcon;
			this.m_elementList = elementList;
			this.xmlHelper.LoadXml(this.path, "Root");
		}

		private void btnOk_Click(object sender, EventArgs e)
		{
			if (this.rbtnAreaDraw.Checked)
			{
				this.m_CheckIndex = 0;
			}
			else if (this.rbtAreaSel.Checked)
			{
				this.m_CheckIndex = 1;
			}
			else if (this.rbtnFloorLevel.Checked)
			{
				this.m_CheckIndex = 2;
			}
			else if (this.rbtnRoom.Checked)
			{
				this.m_CheckIndex = 3;
			}
			this.SaveDlgData();
			base.DialogResult = DialogResult.OK;
		}

		private void btnCancel_Click(object sender, EventArgs e)
		{
			this.SaveDlgData();
			base.Close();
		}

		public int getSelectedType()
		{
			return this.m_CheckIndex;
		}

		private void btnSelCategory_Click(object sender, EventArgs e)
		{
			SelectCategrayType selectCategrayType = new SelectCategrayType(this.m_elementList);
			selectCategrayType.initCategoryItemList();
			CategoryTypeSelForm categoryTypeSelForm = new CategoryTypeSelForm(selectCategrayType, true);
			categoryTypeSelForm.ShowDialog();
		}

		private void SaveDlgData()
		{
			this.xmlHelper.SelectNode(Path.Combine("Root", "CheckTypeSelectForm"));
			this.xmlHelper.SelectNode(Path.Combine("Root", "CheckTypeSelectForm", "Params"));
			this.xmlHelper.SetAttribute("RadioCheck", this.m_CheckIndex.ToString());
			this.xmlHelper.SetAttribute("X", base.Location.X.ToString());
			this.xmlHelper.SetAttribute("Y", base.Location.Y.ToString());
			this.xmlHelper.SaveXml("");
		}

		private void LoadDlgData()
		{
			this.xmlHelper.SelectNode(Path.Combine("Root", "CheckTypeSelectForm", "Params"));
			string attribute = this.xmlHelper.GetAttribute("RadioCheck");
			if (!string.IsNullOrEmpty(attribute))
			{
				this.m_CheckIndex = Convert.ToInt32(attribute);
			}
			string attribute2 = this.xmlHelper.GetAttribute("X");
			string attribute3 = this.xmlHelper.GetAttribute("Y");
			if (!string.IsNullOrEmpty(attribute2) && !string.IsNullOrEmpty(attribute3))
			{
                base.Location = new System.Drawing.Point(Convert.ToInt32(attribute2), Convert.ToInt32(attribute3));
			}
		}

		private void CheckTypeSelectForm_Load(object sender, EventArgs e)
		{
			this.LoadDlgData();
			switch (this.m_CheckIndex)
			{
			case 0:
				this.rbtnAreaDraw.Checked = true;
				return;
			case 1:
				this.rbtAreaSel.Checked = true;
				return;
			case 2:
				this.rbtnFloorLevel.Checked = true;
				return;
			case 3:
				this.rbtnRoom.Checked = true;
				return;
			default:
				return;
			}
		}

		private void CheckTypeSelectForm_FormClosed(object sender, FormClosedEventArgs e)
		{
			this.SaveDlgData();
			base.Close();
		}

		private const string Root = "Root";

		private const string Node = "CheckTypeSelectForm";

		private const string ChildNode = "Params";

		private const string LocationX = "X";

		private const string LocationY = "Y";

		private const string m_strRadio = "RadioCheck";

		private int m_CheckIndex;

		private YJKCodeBase.XmlUtility.XmlHelper xmlHelper = new YJKCodeBase.XmlUtility.XmlHelper();

		private string path = Path.Combine(Product.WorkingLocation, "CheckTypeSelectForm.xml");

		private List<Element> m_elementList = new List<Element>();
	}
}
